Skip to content

Conversation

GrahamBorland
Copy link

Adds a function to convert a java.time.Clock to a kotlinx.datetime.Clock.

@GrahamBorland GrahamBorland changed the title Add clock converter Add java.time.Clock converter Feb 7, 2023
/**
* Converts this [java.time.Clock][java.time.Clock] to a [kotlinx.datetime.Clock][Clock].
*/
public fun java.time.Clock.toKotlinClock(): Clock = this.let {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use let? Just remove it and return the object directly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, thanks. Fixed. 😄

@ilya-g
Copy link
Member

ilya-g commented Apr 28, 2023

Could you describe cases when such conversion could be useful?

@GrahamBorland
Copy link
Author

When you have a Java clock (e.g. injected from DI on Android) and you want to pass it to a KMP library using kotlinx-datetime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants